<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>webdoc</title>
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
<div class="nav">
    <div class="logo">
        
            webdoc
        
    </div>
<ul><li><a href="../index.html">0.Async</a></li><li><a href="../html/0.editor.html">0.editor</a></li><li><a href="../html/0.module.html">0.module</a></li><li><a href="../html/1.ES2015.html">1.ES2015</a></li><li><a href="../html/2.Promise.html">2.Promise</a></li><li><a href="../html/3.Node.html">3.Node</a></li><li><a href="../html/4.NodeInstall.html">4.NodeInstall</a></li><li><a href="../html/5.REPL.html">5.REPL</a></li><li><a href="../html/6.NodeCore.html">6.NodeCore</a></li><li><a href="../html/7.module&NPM.html">7.module&NPM</a></li><li><a href="../html/8.Encoding.html">8.Encoding</a></li><li><a href="../html/9.Buffer.html">9.Buffer</a></li><li><a href="../html/10.fs.html">10.fs</a></li><li><a href="../html/11.Stream-1.html">11.Stream-1</a></li><li><a href="../html/11.Stream-2.html">11.Stream-2</a></li><li><a href="../html/11.Stream-3.html">11.Stream-3</a></li><li><a href="../html/11.Stream-4.html">11.Stream-4</a></li><li><a href="../html/12-Network-2.html">12-Network-2</a></li><li><a href="../html/12.NetWork-3.html">12.NetWork-3</a></li><li><a href="../html/12.Network-1.html">12.Network-1</a></li><li><a href="../html/13.tcp.html">13.tcp</a></li><li><a href="../html/14.http-1.html">14.http-1</a></li><li><a href="../html/14.http-2.html">14.http-2</a></li><li><a href="../html/15.compress.html">15.compress</a></li><li><a href="../html/16.crypto.html">16.crypto</a></li><li><a href="../html/17.process.html">17.process</a></li><li><a href="../html/18.yargs.html">18.yargs</a></li><li><a href="../html/19.cache.html">19.cache</a></li><li><a href="../html/20.action.html">20.action</a></li><li><a href="../html/21.https.html">21.https</a></li><li><a href="../html/22.cookie.html">22.cookie</a></li><li><a href="../html/23.session.html">23.session</a></li><li><a href="../html/24.express-1.html">24.express-1</a></li><li><a href="../html/24.express-2.html">24.express-2</a></li><li><a href="../html/24.express-3.html">24.express-3</a></li><li><a href="../html/24.express-4.html">24.express-4</a></li><li><a href="../html/25.koa-1.html">25.koa-1</a></li><li><a href="../html/26.webpack-1-basic.html">26.webpack-1-basic</a></li><li><a href="../html/26.webpack-2-optimize.html">26.webpack-2-optimize</a></li><li><a href="../html/26.webpack-3.tapable.html">26.webpack-3.tapable</a></li><li><a href="../html/26.webpack-4-AST.html">26.webpack-4-AST</a></li><li><a href="../html/26.webpack-5-source.html">26.webpack-5-source</a></li><li><a href="../html/26.webpack-6-loader.html">26.webpack-6-loader</a></li><li><a href="../html/26.webpack-7-plugin.html">26.webpack-7-plugin</a></li><li><a href="../html/26.webpack-8-hand.html">26.webpack-8-hand</a></li><li><a href="../html/27.react-1.html">27.react-1</a></li><li><a href="../html/27.react-2.html">27.react-2</a></li><li><a href="../html/27.react-3.html">27.react-3</a></li><li><a href="../html/27.react-4-immutable.html">27.react-4-immutable</a></li><li><a href="../html/27.react-5-react-dom-diff.html">27.react-5-react-dom-diff</a></li><li><a href="../html/27.react-6.html">27.react-6</a></li><li><a href="../html/28.react-mobx.html">28.react-mobx</a></li><li><a href="../html/28.redux-0.html">28.redux-0</a></li><li><a href="../html/28.redux-1.html">28.redux-1</a></li><li><a href="../html/28.redux-2-中间件.html">28.redux-2-中间件</a></li><li><a href="../html/28.redux-3-saga.html">28.redux-3-saga</a></li><li><a href="../html/28.redux-jwt-back.html">28.redux-jwt-back</a></li><li><a href="../html/28.redux-jwt-front.html">28.redux-jwt-front</a></li><li><a href="../html/29.mongodb-1.html">29.mongodb-1</a></li><li><a href="../html/29.mongodb-2.html">29.mongodb-2</a></li><li><a href="../html/29.mongodb-3.html">29.mongodb-3</a></li><li><a href="../html/29.mongodb-4.html">29.mongodb-4</a></li><li><a href="../html/29.mongodb-5.html">29.mongodb-5</a></li><li><a href="../html/29.mongodb-6.html">29.mongodb-6</a></li><li><a href="../html/30.cms-1-mysql.html">30.cms-1-mysql</a></li><li><a href="../html/30.cms-2-mysql.html">30.cms-2-mysql</a></li><li><a href="../html/30.cms-3-mysql.html">30.cms-3-mysql</a></li><li><a href="../html/30.cms-4-egg.html">30.cms-4-egg</a></li><li><a href="../html/30.cms-5-api.html">30.cms-5-api</a></li><li><a href="../html/30.cms-6-roadhog.html">30.cms-6-roadhog</a></li><li><a href="../html/30.cms-7-umi.html">30.cms-7-umi</a></li><li><a href="../html/30.cms-8-dva.html">30.cms-8-dva</a></li><li><a href="../html/30.cms-9-dva.html">30.cms-9-dva</a></li><li><a href="../html/30.cms-10-dva.html">30.cms-10-dva</a></li><li><a href="../html/30.cms-11-front.html">30.cms-11-front</a></li><li><a href="../html/31.cms-12-api.html">31.cms-12-api</a></li><li><a href="../html/31.cms-13-front.html">31.cms-13-front</a></li><li><a href="../html/31.cms-14-deploy.html">31.cms-14-deploy</a></li><li><a href="../html/32.ant.html">32.ant</a></li><li><a href="../html/33.redis.html">33.redis</a></li><li><a href="../html/34.unittest.html">34.unittest</a></li><li><a href="../html/35.jwt.html">35.jwt</a></li><li><a href="../html/36.websocket-1.html">36.websocket-1</a></li><li><a href="../html/36.websocket-2.html">36.websocket-2</a></li><li><a href="../html/38.chat-api-1.html">38.chat-api-1</a></li><li><a href="../html/38.chat-api-2.html">38.chat-api-2</a></li><li class="active"><a href="../html/38.chat-3.html">38.chat-3</a></li><li><a href="../html/38.chat-api-3.html">38.chat-api-3</a></li><li><a href="../html/38.chat.html">38.chat</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/39.crawl-0.html">39.crawl-0</a></li><li><a href="../html/39.crawl-1.html">39.crawl-1</a></li><li><a href="../html/39.crawl-2.html">39.crawl-2</a></li><li><a href="../html/40.deploy.html">40.deploy</a></li><li><a href="../html/41.safe.html">41.safe</a></li><li><a href="../html/42.test.html">42.test</a></li><li><a href="../html/43.nginx.html">43.nginx</a></li><li><a href="../html/44.enzyme.html">44.enzyme</a></li><li><a href="../html/45.docker.html">45.docker</a></li><li><a href="../html/46.elastic.html">46.elastic</a></li><li><a href="../html/47.oauth.html">47.oauth</a></li><li><a href="../html/48.wxpay.html">48.wxpay</a></li><li><a href="../html/49.nunjucks.html">49.nunjucks</a></li><li><a href="../html/50.ketang.html">50.ketang</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/51.typescript.html">51.typescript</a></li><li><a href="../html/52.UML.html">52.UML</a></li><li><a href="../html/53.design.html">53.design</a></li><li><a href="../html/index.html">index</a></li></ul></div>


<div class="warpper">

    <div class="page-toc">
        <ul><li><a href="#t01. 初始化项目">1. 初始化项目</a></li><li><a href="#t12.绘制登录表单">2.绘制登录表单</a><ul><li><a href="#t22.1 login/index.js">2.1 login/index.js</a></li></ul></li><li><a href="#t33. 实现登录">3. 实现登录</a><ul><li><a href="#t43.1  src/pages/login/index.js">3.1  src/pages/login/index.js</a></li><li><a href="#t53.2 src/pages/login/models/login.js">3.2 src/pages/login/models/login.js</a></li><li><a href="#t63.3 src/pages/login/services/login.js">3.3 src/pages/login/services/login.js</a></li><li><a href="#t73.4 src/utils/request.js">3.4 src/utils/request.js</a></li></ul></li><li><a href="#t84. 实现房间列表功能">4. 实现房间列表功能</a><ul><li><a href="#t94.1 pages/rooms/index.js">4.1 pages/rooms/index.js</a></li><li><a href="#t104.2 pages/rooms/models/rooms.js">4.2 pages/rooms/models/rooms.js</a></li><li><a href="#t114.3 services/rooms.js">4.3 services/rooms.js</a></li></ul></li><li><a href="#t125. 聊天页面">5. 聊天页面</a><ul><li><a href="#t135.1 src/pages/login/models/login.js">5.1 src/pages/login/models/login.js</a></li><li><a href="#t145.2 src/pages/login/services/login.js">5.2 src/pages/login/services/login.js</a></li><li><a href="#t155.3 src/pages/rooms/index.js">5.3 src/pages/rooms/index.js</a></li><li><a href="#t165.4 pages/messages/$id.js">5.4 pages/messages/$id.js</a></li><li><a href="#t175.5 src/pages/messages/models/messages.js">5.5 src/pages/messages/models/messages.js</a></li></ul></li><li><a href="#t186. 支持表情">6. 支持表情</a><ul><li><a href="#t196.1 src/pages/messages/$id.js">6.1 src/pages/messages/$id.js</a></li><li><a href="#t206.2 src/pages/messages/expressions.js">6.2 src/pages/messages/expressions.js</a></li></ul></li><li><a href="#t21参考">参考</a></li></ul>
    </div>
    
    <div class="content markdown-body">
        <h2 id="t01. &#x521D;&#x59CB;&#x5316;&#x9879;&#x76EE;">1. &#x521D;&#x59CB;&#x5316;&#x9879;&#x76EE; <a href="#t01. &#x521D;&#x59CB;&#x5316;&#x9879;&#x76EE;"> # </a></h2>
<pre><code class="lang-js">dva <span class="hljs-keyword">new</span> chat
cd chat 
npm i 
npm start
cnpm i styled-components -S
</code></pre>
<h2 id="t12.&#x7ED8;&#x5236;&#x767B;&#x5F55;&#x8868;&#x5355;">2.&#x7ED8;&#x5236;&#x767B;&#x5F55;&#x8868;&#x5355; <a href="#t12.&#x7ED8;&#x5236;&#x767B;&#x5F55;&#x8868;&#x5355;"> # </a></h2>
<h3 id="t22.1 login/index.js">2.1 login/index.js <a href="#t22.1 login/index.js"> # </a></h3>
<p>src/pages/login/index.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React,{Component} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react&apos;</span>;
<span class="hljs-keyword">import</span> styled <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;styled-components&apos;</span>;
<span class="hljs-keyword">import</span> {connect} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;dva&apos;</span>;
<span class="hljs-keyword">import</span> {Form,Input,message,Button} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;antd&apos;</span>;
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Login</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span></span>{
    handleSubmit=<span class="hljs-function">(<span class="hljs-params">event</span>) =&gt;</span> {
        event.preventDefault();
        <span class="hljs-keyword">this</span>.loginForm.props.form.validateFields(<span class="hljs-function">(<span class="hljs-params">err,values</span>) =&gt;</span> {
            <span class="hljs-keyword">if</span> (err) {
                <span class="hljs-keyword">return</span> message.warn(<span class="hljs-string">&apos;&#x767B;&#x5F55;&#x4FE1;&#x606F;&#x8F93;&#x5165;&#x4E0D;&#x5408;&#x6CD5;!&#x8BF7;&#x91CD;&#x65B0;&#x8F93;&#x5165;!&apos;</span>);
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">this</span>.props.dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;login/login&apos;</span>});
            }
        });
    }
    render() {
        <span class="hljs-keyword">return</span> (
            &lt;WrappedLayout&gt;
                &lt;WrappedLoginForm
                    handleSubmit={this.handleSubmit}
                    wrappedComponentRef={inst=&gt;this.loginForm=inst}
                /&gt;
            &lt;/WrappedLayout&gt;
       )
   }
}
class LoginForm extends Component{
    render() {
        const {form: {getFieldDecorator},handleSubmit}=this.props;
        return (
            &lt;Form onSubmit={handleSubmit}&gt;
                &lt;h4&gt;&#x8BF7;&#x8F93;&#x5165;&#x90AE;&#x7BB1;&#x767B;&#x5F55;&lt;/h4&gt;
                &lt;Form.Item&gt;
                    {
                      getFieldDecorator(&apos;email&apos;,{
                        rules: [
                            {required:true,message:&apos;&#x8BF7;&#x8F93;&#x5165;&#x90AE;&#x7BB1;&#x5730;&#x5740;&apos;},
                            {type:&apos;email&apos;,message:&apos;&#x8BF7;&#x8F93;&#x5165;&#x5408;&#x6CD5;&#x7684;&#x90AE;&#x7BB1;&#x5730;&#x5740;&apos;}
                        ]
                      })(&lt;Input placeholder=&quot;&#x8BF7;&#x8F93;&#x5165;&#x90AE;&#x7BB1;&quot;/&gt;)
                    }
                &lt;/Form.Item&gt;
                &lt;Form.Item&gt;
                    &lt;Button htmlType=&quot;submit&quot; type=&quot;primary&quot;&gt;&#x767B;&#x5F55;&lt;/Button&gt;
                &lt;/Form.Item&gt;
            &lt;/Form&gt;
        )
    }
}
const WrappedLoginForm =  Form.create()(LoginForm);
const WrappedLayout=styled.div`
  width:100%;
  height:100%;
  display:flex;
  justify-content:center;
  align-items:center;
  form {
      width:300px;
      margin-top:-500px;
      padding:20px;
      border:1px solid #999;
      border-radius:5px;
      box-shadow:1px 1px 2px 1px,-1px -1px 2px 1px;
      h4{
          text-align:center;
          font-weight:normal;
      }
      button{
          width:100%;
      }
  }
`

export default connect(
    state=&gt;state.login
)(Login);
</code></pre>
<h2 id="t33. &#x5B9E;&#x73B0;&#x767B;&#x5F55;">3. &#x5B9E;&#x73B0;&#x767B;&#x5F55; <a href="#t33. &#x5B9E;&#x73B0;&#x767B;&#x5F55;"> # </a></h2>
<h3 id="t43.1  src/pages/login/index.js">3.1  src/pages/login/index.js <a href="#t43.1  src/pages/login/index.js"> # </a></h3>
<p>src/pages/login/index.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React,{Component} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react&apos;</span>;
<span class="hljs-keyword">import</span> styled <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;styled-components&apos;</span>;
<span class="hljs-keyword">import</span> {connect} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;dva&apos;</span>;
<span class="hljs-keyword">import</span> {Form,Input,message,Button} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;antd&apos;</span>;
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Login</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span></span>{
    handleSubmit=<span class="hljs-function">(<span class="hljs-params">event</span>) =&gt;</span> {
        event.preventDefault();
        <span class="hljs-keyword">this</span>.loginForm.props.form.validateFields(<span class="hljs-function">(<span class="hljs-params">err,values</span>) =&gt;</span> {
            <span class="hljs-keyword">if</span> (err) {
                <span class="hljs-keyword">return</span> message.warn(<span class="hljs-string">&apos;&#x767B;&#x5F55;&#x4FE1;&#x606F;&#x8F93;&#x5165;&#x4E0D;&#x5408;&#x6CD5;!&#x8BF7;&#x91CD;&#x65B0;&#x8F93;&#x5165;!&apos;</span>);
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">this</span>.props.dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;login/login&apos;</span>,<span class="hljs-attr">payload</span>:values});
            }
        });
    }
    render() {
        <span class="hljs-keyword">return</span> (
            &lt;WrappedLayout&gt;
                &lt;WrappedLoginForm
                    handleSubmit={this.handleSubmit}
                    wrappedComponentRef={inst=&gt;this.loginForm=inst}
                /&gt;
            &lt;/WrappedLayout&gt;
       )
   }
}
class LoginForm extends Component{
    render() {
        const {form: {getFieldDecorator},handleSubmit}=this.props;
        return (
            &lt;Form onSubmit={handleSubmit}&gt;
                &lt;h4&gt;&#x8BF7;&#x8F93;&#x5165;&#x90AE;&#x7BB1;&#x767B;&#x5F55;&lt;/h4&gt;
                &lt;Form.Item&gt;
                    {
                      getFieldDecorator(&apos;email&apos;,{
                        rules: [
                            {required:true,message:&apos;&#x8BF7;&#x8F93;&#x5165;&#x90AE;&#x7BB1;&#x5730;&#x5740;&apos;},
                            {type:&apos;email&apos;,message:&apos;&#x8BF7;&#x8F93;&#x5165;&#x5408;&#x6CD5;&#x7684;&#x90AE;&#x7BB1;&#x5730;&#x5740;&apos;}
                        ]
                      })(&lt;Input placeholder=&quot;&#x8BF7;&#x8F93;&#x5165;&#x90AE;&#x7BB1;&quot;/&gt;)
                    }
                &lt;/Form.Item&gt;
                &lt;Form.Item&gt;
                    &lt;Button htmlType=&quot;submit&quot; type=&quot;primary&quot;&gt;&#x767B;&#x5F55;&lt;/Button&gt;
                &lt;/Form.Item&gt;
            &lt;/Form&gt;
        )
    }
}
const WrappedLoginForm =  Form.create()(LoginForm);
const WrappedLayout=styled.div`
  width:100%;
  height:100%;
  display:flex;
  justify-content:center;
  align-items:center;
  form {
      width:300px;
      padding:20px;
      border:1px solid #999;
      border-radius:5px;
      box-shadow:1px 1px 2px 1px,-1px -1px 2px 1px;
      h4{
          text-align:center;
          font-weight:normal;
      }
      button{
          width:100%;
      }
  }
`

export default connect(
    state=&gt;state.login
)(Login);
</code></pre>
<h3 id="t53.2 src/pages/login/models/login.js">3.2 src/pages/login/models/login.js <a href="#t53.2 src/pages/login/models/login.js"> # </a></h3>
<p>src/pages/login/models/login.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> service <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;../services/login&apos;</span>;
<span class="hljs-keyword">import</span> {routerRedux} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;dva/router&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {

    <span class="hljs-attr">namespace</span>: <span class="hljs-string">&apos;login&apos;</span>,

    <span class="hljs-attr">state</span>: {
        <span class="hljs-attr">user</span>: <span class="hljs-literal">null</span>,
        <span class="hljs-attr">error</span>:<span class="hljs-literal">null</span>
    },

    <span class="hljs-attr">subscriptions</span>: {
      setup({ dispatch, history }) {
      },
    },

    <span class="hljs-attr">effects</span>: {
        *login({payload},{call,put}) {
            <span class="hljs-keyword">const</span> {data,error,code}=<span class="hljs-keyword">yield</span> call(service.login,payload);
             <span class="hljs-keyword">if</span> (code == <span class="hljs-number">0</span>) {
                <span class="hljs-keyword">yield</span> put({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;setUser&apos;</span>,<span class="hljs-attr">payload</span>:data});
                <span class="hljs-keyword">yield</span> put(routerRedux.push(<span class="hljs-string">&apos;/rooms&apos;</span>));
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">yield</span> put({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;setError&apos;</span>,<span class="hljs-attr">payload</span>:error});
            } 
      }
    },

    <span class="hljs-attr">reducers</span>: {
        setUser(state,{payload}) {
          <span class="hljs-keyword">return</span> { ...state, <span class="hljs-attr">user</span>:payload };
        },
        setError(state,{payload}) {
          <span class="hljs-keyword">return</span> { ...state, <span class="hljs-attr">error</span>:payload };
      }
    },
};
</code></pre>
<h3 id="t63.3 src/pages/login/services/login.js">3.3 src/pages/login/services/login.js <a href="#t63.3 src/pages/login/services/login.js"> # </a></h3>
<p>src/pages/login/services/login.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> request <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;../../../utils/request&apos;</span>;

<span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">login</span>(<span class="hljs-params">payload</span>) </span>{
    <span class="hljs-keyword">return</span> request(<span class="hljs-string">&apos;/login&apos;</span>,{
        <span class="hljs-attr">method</span>: <span class="hljs-string">&apos;POST&apos;</span>, 
        <span class="hljs-attr">body</span>:<span class="hljs-built_in">JSON</span>.stringify(payload)
    });
}
</code></pre>
<h3 id="t73.4 src/utils/request.js">3.4 src/utils/request.js <a href="#t73.4 src/utils/request.js"> # </a></h3>
<p>src/utils/request.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> BaseUrl=<span class="hljs-string">&apos;http://localhost:7001&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">request</span>(<span class="hljs-params">url, options</span>) </span>{
  <span class="hljs-keyword">return</span> fetch(BaseUrl+url, options)
    .then(checkStatus)
    .then(parseJSON)
    .catch(<span class="hljs-function"><span class="hljs-params">err</span> =&gt;</span> ({ err }));
}
</code></pre>
<h2 id="t84. &#x5B9E;&#x73B0;&#x623F;&#x95F4;&#x5217;&#x8868;&#x529F;&#x80FD;">4. &#x5B9E;&#x73B0;&#x623F;&#x95F4;&#x5217;&#x8868;&#x529F;&#x80FD; <a href="#t84. &#x5B9E;&#x73B0;&#x623F;&#x95F4;&#x5217;&#x8868;&#x529F;&#x80FD;"> # </a></h2>
<h3 id="t94.1 pages/rooms/index.js">4.1 pages/rooms/index.js <a href="#t94.1 pages/rooms/index.js"> # </a></h3>
<p>pages/rooms/index.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React,{Component} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react&apos;</span>;
<span class="hljs-keyword">import</span> styled <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;styled-components&apos;</span>;
<span class="hljs-keyword">import</span> {connect} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;dva&apos;</span>;
<span class="hljs-keyword">import</span> {Form,Input,message,Button,Layout,Menu,Breadcrumb,Card,Row,Col} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;antd&apos;</span>;
<span class="hljs-keyword">import</span> logo <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;../../assets/logo.png&apos;</span>;
<span class="hljs-keyword">import</span> styles <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./index.less&apos;</span>;
<span class="hljs-keyword">import</span> Link <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;umi/link&apos;</span>;
<span class="hljs-keyword">const</span> {Header,Content,Footer}=Layout;
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Rooms</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span></span>{
    handleSubmit=<span class="hljs-function">(<span class="hljs-params">event</span>) =&gt;</span> {
        event.preventDefault();
        <span class="hljs-keyword">this</span>.loginForm.props.form.validateFields(<span class="hljs-function">(<span class="hljs-params">err,values</span>) =&gt;</span> {
            <span class="hljs-keyword">if</span> (err) {
                <span class="hljs-keyword">return</span> message.warn(<span class="hljs-string">&apos;&#x767B;&#x5F55;&#x4FE1;&#x606F;&#x8F93;&#x5165;&#x4E0D;&#x5408;&#x6CD5;!&#x8BF7;&#x91CD;&#x65B0;&#x8F93;&#x5165;!&apos;</span>);
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">this</span>.props.dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;login/login&apos;</span>,<span class="hljs-attr">payload</span>:values});
            }
        });
    }
    handleKeywordChange=<span class="hljs-function">(<span class="hljs-params">event</span>) =&gt;</span> {
        <span class="hljs-keyword">this</span>.props.dispatch({<span class="hljs-attr">type</span>: <span class="hljs-string">&apos;rooms/setKeyword&apos;</span>,<span class="hljs-attr">payload</span>: event.target.value});
    }
    createRoom=<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
        <span class="hljs-keyword">this</span>.props.dispatch({<span class="hljs-attr">type</span>: <span class="hljs-string">&apos;rooms/createRoom&apos;</span>});
    }
    render() {
        <span class="hljs-keyword">const</span> {list=[]}=<span class="hljs-keyword">this</span>.props;
        <span class="hljs-keyword">return</span> (
            &lt;Layout&gt;
                &lt;Header&gt;
                    &lt;img src={logo} className={styles.logo}/&gt;
                    &lt;Menu
                        theme=&quot;dark&quot;
                        mode=&quot;horizontal&quot;
                        defaultSelectedKeys={[&apos;/rooms&apos;]}
                        style={{lineHeight:&apos;64px&apos;}}
                    &gt;
                        &lt;Menu.Item key=&quot;/rooms&quot;&gt;&#x623F;&#x95F4;&#x5217;&#x8868;&lt;/Menu.Item&gt;
                    &lt;/Menu&gt;    
                &lt;/Header&gt;
                &lt;Content style={{padding:&apos;0 50px&apos;}}&gt;
                    &lt;Breadcrumb style={{margin: &apos;16px 0&apos;}}&gt;
                        &lt;Breadcrumb.Item&gt;&#x623F;&#x95F4;&#x5217;&#x8868;&lt;/Breadcrumb.Item&gt;
                    &lt;/Breadcrumb&gt;
                    &lt;SearchForm
                          createRoom={this.createRoom}
                          handleKeywordChange={this.handleKeywordChange}
                          size={list.length}
                        /&gt;
                    &lt;Card&gt;
                        &lt;Row  gutter={16}&gt;
                            {
                                list.map(room =&gt; (
                                    &lt;Col span={6} style={{padding:&apos;5px 0&apos;}}&gt;
                                        &lt;Link to={`/rooms/${room._id}`}&gt;
                                            &lt;Card
                                                hoverable
                                                style={{ width: 240 }}
                                                cover={&lt;img alt=&quot;example&quot; src=&quot;https://os.alipayobjects.com/rmsportal/QBnOOoLaAfKPirc.png&quot; /&gt;}
                                            &gt;
                                                &lt;Card.Meta
                                                    title={room.name}
                                                /&gt;
                                            &lt;/Card&gt;
                                        &lt;/Link&gt;
                                    &lt;/Col&gt;
                                ))
                            }
                        &lt;/Row&gt;
                    &lt;/Card&gt;
                &lt;/Content&gt;
                &lt;Footer style={{textAlign:&apos;center&apos;}}&gt;
                    &#x73E0;&#x5CF0;&#x57F9;&#x8BAD; @2018 
                &lt;/Footer&gt;
            &lt;/Layout&gt;
       )
   }
}
class SearchForm extends Component{
    render() {
        const {handleKeywordChange,createRoom,size}=this.props;
        const formItemLayout={
            labelCol: {span: 8},
            wrapperCol:{span:16}
        }
        return (
            &lt;Form&gt;
                &lt;Form.Item label=&quot;&#x8BF7;&#x8F93;&#x5165;&#x623F;&#x95F4;&#x540D;&#x5173;&#x952E;&#x5B57;&quot; {...formItemLayout}&gt;
                    &lt;Row gutter={18}&gt;
                        &lt;Col span={12}&gt;&lt;Input placeholder=&quot;&#x8BF7;&#x8F93;&#x5165;&#x5173;&#x952E;&#x5B57;&quot; onChange={handleKeywordChange} /&gt;&lt;/Col&gt;
                        &lt;Col span={12}&gt;
                            {size==0&amp;&amp;&lt;Button onClick={createRoom}&gt;&#x521B;&#x5EFA;&#x623F;&#x95F4;&lt;/Button&gt;}

                        &lt;/Col&gt;
                    &lt;/Row&gt;
                &lt;/Form.Item&gt;
            &lt;/Form&gt;
        )
    }
}

export default connect(
    state =&gt; ({
        list: state.rooms.list.filter(item =&gt; {
            return item.name&amp;&amp;item.name.indexOf(state.rooms.keyword)!=-1;
        })
    })
)(Rooms);
</code></pre>
<h3 id="t104.2 pages/rooms/models/rooms.js">4.2 pages/rooms/models/rooms.js <a href="#t104.2 pages/rooms/models/rooms.js"> # </a></h3>
<p>pages/rooms/models/rooms.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> service <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;../services/rooms&apos;</span>;
<span class="hljs-keyword">import</span> {routerRedux} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;dva/router&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {

    <span class="hljs-attr">namespace</span>: <span class="hljs-string">&apos;rooms&apos;</span>,

    <span class="hljs-attr">state</span>: {
        <span class="hljs-attr">list</span>: [],
        <span class="hljs-attr">error</span>: <span class="hljs-literal">null</span>,
        <span class="hljs-attr">keyword</span>:<span class="hljs-string">&apos;&apos;</span>
    },

    <span class="hljs-attr">subscriptions</span>: {
        setup({dispatch,history}) {
            history.listen(<span class="hljs-function">(<span class="hljs-params">{pathname,query}</span>) =&gt;</span> {
                <span class="hljs-keyword">if</span> (pathname == <span class="hljs-string">&apos;/rooms&apos;</span>) {
                    dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;list&apos;</span>});
                }
            });
      },
    },

    <span class="hljs-attr">effects</span>: {
        *list({payload},{call,put}) {
            <span class="hljs-keyword">const</span> {data,error,code}=<span class="hljs-keyword">yield</span> call(service.list,payload);
             <span class="hljs-keyword">if</span> (code == <span class="hljs-number">0</span>) {
                <span class="hljs-keyword">yield</span> put({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;listed&apos;</span>,<span class="hljs-attr">payload</span>:data});
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">yield</span> put({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;setError&apos;</span>,<span class="hljs-attr">payload</span>:error});
            } 
        },
        *createRoom({},{call,put,select}) {
            <span class="hljs-keyword">let</span> keyword=<span class="hljs-keyword">yield</span> select(<span class="hljs-function"><span class="hljs-params">state</span> =&gt;</span> state.rooms.keyword);
            <span class="hljs-keyword">const</span> {data,error,code}=<span class="hljs-keyword">yield</span> call(service.createRoom,{<span class="hljs-attr">name</span>:keyword});
             <span class="hljs-keyword">if</span> (code == <span class="hljs-number">0</span>) {
                <span class="hljs-keyword">yield</span> put({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;list&apos;</span>});
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">yield</span> put({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;setError&apos;</span>,<span class="hljs-attr">payload</span>:error});
            } 
      }
    },

    <span class="hljs-attr">reducers</span>: {
        listed(state,{payload}) {
          <span class="hljs-keyword">return</span> { ...state, <span class="hljs-attr">list</span>:payload };
        },
        setError(state,{payload}) {
          <span class="hljs-keyword">return</span> { ...state, <span class="hljs-attr">error</span>:payload };
        },
        setKeyword(state,{payload}) {
            <span class="hljs-keyword">return</span> {...state,<span class="hljs-attr">keyword</span>:payload};
        }
    },
};
</code></pre>
<h3 id="t114.3 services/rooms.js">4.3 services/rooms.js <a href="#t114.3 services/rooms.js"> # </a></h3>
<p>services/rooms.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> request <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;../../../utils/request&apos;</span>;

<span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">list</span>(<span class="hljs-params">keyword=<span class="hljs-string">&apos;&apos;</span></span>) </span>{
    <span class="hljs-keyword">return</span> request(<span class="hljs-string">`/rooms`</span>,{
        <span class="hljs-attr">method</span>: <span class="hljs-string">&apos;GET&apos;</span>
    });
}

<span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">createRoom</span>(<span class="hljs-params">values</span>) </span>{
    <span class="hljs-keyword">return</span> request(<span class="hljs-string">`/rooms`</span>,{
        <span class="hljs-attr">method</span>: <span class="hljs-string">&apos;POST&apos;</span>,
        <span class="hljs-attr">headers</span>:{<span class="hljs-string">&quot;Content-Type&quot;</span>:<span class="hljs-string">&quot;application/json&quot;</span>},
        <span class="hljs-attr">body</span>:<span class="hljs-built_in">JSON</span>.stringify(values)
    });
}
</code></pre>
<h2 id="t125. &#x804A;&#x5929;&#x9875;&#x9762;">5. &#x804A;&#x5929;&#x9875;&#x9762; <a href="#t125. &#x804A;&#x5929;&#x9875;&#x9762;"> # </a></h2>
<h3 id="t135.1 src/pages/login/models/login.js">5.1 src/pages/login/models/login.js <a href="#t135.1 src/pages/login/models/login.js"> # </a></h3>
<p>src/pages/login/models/login.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> service <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;../services/login&apos;</span>;
<span class="hljs-keyword">import</span> {routerRedux} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;dva/router&apos;</span>;
<span class="hljs-keyword">import</span> {decode} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;jsonwebtoken&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {

    <span class="hljs-attr">namespace</span>: <span class="hljs-string">&apos;login&apos;</span>,

    <span class="hljs-attr">state</span>: {
        <span class="hljs-attr">user</span>: <span class="hljs-literal">null</span>,
        <span class="hljs-attr">token</span>:<span class="hljs-literal">null</span>,
        <span class="hljs-attr">error</span>:<span class="hljs-literal">null</span>
    },

    <span class="hljs-attr">subscriptions</span>: {
      setup({ dispatch, history }) {
      },
    },

    <span class="hljs-attr">effects</span>: {
        *login({payload},{call,put}) {
            <span class="hljs-keyword">const</span> {<span class="hljs-attr">data</span>:token,error,code}=<span class="hljs-keyword">yield</span> call(service.login,payload);
            <span class="hljs-keyword">if</span> (code==<span class="hljs-number">0</span>) {
                <span class="hljs-keyword">let</span> user=decode(token);        
                localStorage.setItem(<span class="hljs-string">&apos;token&apos;</span>,token);
                <span class="hljs-keyword">yield</span> put({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;setUser&apos;</span>,<span class="hljs-attr">payload</span>:user});
                <span class="hljs-keyword">yield</span> put(routerRedux.push(<span class="hljs-string">&apos;/rooms&apos;</span>));
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">yield</span> put({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;setError&apos;</span>,<span class="hljs-attr">payload</span>:error});
            } 
        },
        *validate({payload},{call,put}) {
            <span class="hljs-keyword">let</span> token=localStorage.getItem(<span class="hljs-string">&apos;token&apos;</span>)||<span class="hljs-string">&apos;&apos;</span>;
            <span class="hljs-keyword">if</span> (token) {
                <span class="hljs-keyword">let</span> user=decode(token);    
                <span class="hljs-keyword">yield</span> put({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;setUser&apos;</span>,<span class="hljs-attr">payload</span>:user});
            }<span class="hljs-keyword">else</span>{
                <span class="hljs-keyword">yield</span> put(routerRedux.push(<span class="hljs-string">&apos;/login&apos;</span>));
            }
        },
        *logout({payload},{call,put}) {
            <span class="hljs-keyword">yield</span> put({<span class="hljs-attr">type</span>: <span class="hljs-string">&apos;setUser&apos;</span>,<span class="hljs-attr">payload</span>: <span class="hljs-literal">null</span>});
            localStorage.removeItem(<span class="hljs-string">&apos;token&apos;</span>);
            <span class="hljs-keyword">yield</span> put(routerRedux.push(<span class="hljs-string">&apos;/login&apos;</span>));
        }
    },

    <span class="hljs-attr">reducers</span>: {
        setUser(state,{payload}) {
          <span class="hljs-keyword">return</span> { ...state, <span class="hljs-attr">user</span>:payload };
        },
        setError(state,{payload}) {
          <span class="hljs-keyword">return</span> { ...state, <span class="hljs-attr">error</span>:payload };
      }
    },
};
</code></pre>
<h3 id="t145.2 src/pages/login/services/login.js">5.2 src/pages/login/services/login.js <a href="#t145.2 src/pages/login/services/login.js"> # </a></h3>
<p>src/pages/login/services/login.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> request <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;../../../utils/request&apos;</span>;

<span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">login</span>(<span class="hljs-params">payload</span>) </span>{
    <span class="hljs-keyword">return</span> request(<span class="hljs-string">&apos;/login&apos;</span>,{
        <span class="hljs-attr">method</span>: <span class="hljs-string">&apos;POST&apos;</span>, 
        <span class="hljs-attr">headers</span>:{<span class="hljs-string">&quot;Content-Type&quot;</span>:<span class="hljs-string">&quot;application/json&quot;</span>},
        <span class="hljs-attr">body</span>:<span class="hljs-built_in">JSON</span>.stringify(payload)
    });
}
</code></pre>
<h3 id="t155.3 src/pages/rooms/index.js">5.3 src/pages/rooms/index.js <a href="#t155.3 src/pages/rooms/index.js"> # </a></h3>
<p>src/pages/rooms/index.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React,{Component} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react&apos;</span>;
<span class="hljs-keyword">import</span> styled <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;styled-components&apos;</span>;
<span class="hljs-keyword">import</span> {connect} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;dva&apos;</span>;
<span class="hljs-keyword">import</span> {Form,Input,message,Button,Layout,Menu,Breadcrumb,Card,Row,Col} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;antd&apos;</span>;
<span class="hljs-keyword">import</span> logo <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;../../assets/logo.png&apos;</span>;
<span class="hljs-keyword">import</span> styles <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./index.less&apos;</span>;
<span class="hljs-keyword">import</span> Link <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;umi/link&apos;</span>;
<span class="hljs-keyword">const</span> {Header,Content,Footer}=Layout;
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Rooms</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span></span>{
    handleSubmit=<span class="hljs-function">(<span class="hljs-params">event</span>) =&gt;</span> {
        event.preventDefault();
        <span class="hljs-keyword">this</span>.loginForm.props.form.validateFields(<span class="hljs-function">(<span class="hljs-params">err,values</span>) =&gt;</span> {
            <span class="hljs-keyword">if</span> (err) {
                <span class="hljs-keyword">return</span> message.warn(<span class="hljs-string">&apos;&#x767B;&#x5F55;&#x4FE1;&#x606F;&#x8F93;&#x5165;&#x4E0D;&#x5408;&#x6CD5;!&#x8BF7;&#x91CD;&#x65B0;&#x8F93;&#x5165;!&apos;</span>);
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">this</span>.props.dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;login/login&apos;</span>,<span class="hljs-attr">payload</span>:values});
            }
        });
    }
    handleKeywordChange=<span class="hljs-function">(<span class="hljs-params">event</span>) =&gt;</span> {
        <span class="hljs-keyword">this</span>.props.dispatch({<span class="hljs-attr">type</span>: <span class="hljs-string">&apos;rooms/setKeyword&apos;</span>,<span class="hljs-attr">payload</span>: event.target.value});
    }
    createRoom=<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
        <span class="hljs-keyword">this</span>.props.dispatch({<span class="hljs-attr">type</span>: <span class="hljs-string">&apos;rooms/createRoom&apos;</span>});
    }
    render() {
        <span class="hljs-keyword">const</span> {list=[],user}=<span class="hljs-keyword">this</span>.props;
        <span class="hljs-keyword">return</span> (
            &lt;Layout&gt;
                &lt;Header&gt;
                    &lt;img src={logo} className={styles.logo}/&gt;
                    &lt;Menu
                        theme=&quot;dark&quot;
                        mode=&quot;horizontal&quot;
                        defaultSelectedKeys={[&apos;/rooms&apos;]}
                        style={{lineHeight:&apos;64px&apos;}}
                    &gt;
                        &lt;Menu.Item key=&quot;/rooms&quot;&gt;
                        &#x623F;&#x95F4;&#x5217;&#x8868;
                                &#x7528;&#x6237;: {user&amp;&amp;user.name}
                        &lt;/Menu.Item&gt;
                    &lt;/Menu&gt;    
                &lt;/Header&gt;
                &lt;Content style={{padding:&apos;0 50px&apos;}}&gt;
                    &lt;Breadcrumb style={{margin: &apos;16px 0&apos;}}&gt;
                        &lt;Breadcrumb.Item&gt;&#x623F;&#x95F4;&#x5217;&#x8868;: {user&amp;&amp;user.name}&lt;/Breadcrumb.Item&gt;
                    &lt;/Breadcrumb&gt;
                    &lt;SearchForm
                          createRoom={this.createRoom}
                          handleKeywordChange={this.handleKeywordChange}
                          size={list.length}
                        /&gt;
                    &lt;Card&gt;
                        &lt;Row  gutter={16}&gt;
                            {
                                list.map(room =&gt; (
                                    &lt;Col key={room._id} span={6} style={{padding:&apos;5px 0&apos;}}&gt;
                                        &lt;Link to={`/messages/${room._id}`}&gt;
                                            &lt;Card
                                                hoverable
                                                style={{ width: 240 }}
                                                cover={&lt;img alt=&quot;example&quot; src=&quot;https://os.alipayobjects.com/rmsportal/QBnOOoLaAfKPirc.png&quot; /&gt;}
                                            &gt;
                                                &lt;Card.Meta
                                                    title={room.name}
                                                /&gt;
                                            &lt;/Card&gt;
                                        &lt;/Link&gt;
                                    &lt;/Col&gt;
                                ))
                            }
                        &lt;/Row&gt;
                    &lt;/Card&gt;
                &lt;/Content&gt;
                &lt;Footer style={{textAlign:&apos;center&apos;}}&gt;
                    &#x73E0;&#x5CF0;&#x57F9;&#x8BAD; @2018 
                &lt;/Footer&gt;
            &lt;/Layout&gt;
       )
   }
}
class SearchForm extends Component{
    render() {
        const {handleKeywordChange,createRoom,size}=this.props;
        const formItemLayout={
            labelCol: {span: 8},
            wrapperCol:{span:16}
        }
        return (
            &lt;Form&gt;
                &lt;Form.Item label=&quot;&#x8BF7;&#x8F93;&#x5165;&#x623F;&#x95F4;&#x540D;&#x5173;&#x952E;&#x5B57;&quot; {...formItemLayout}&gt;
                    &lt;Row gutter={18}&gt;
                        &lt;Col span={12}&gt;&lt;Input placeholder=&quot;&#x8BF7;&#x8F93;&#x5165;&#x5173;&#x952E;&#x5B57;&quot; onChange={handleKeywordChange} /&gt;&lt;/Col&gt;
                        &lt;Col span={12}&gt;
                            {size==0&amp;&amp;&lt;Button onClick={createRoom}&gt;&#x521B;&#x5EFA;&#x623F;&#x95F4;&lt;/Button&gt;}

                        &lt;/Col&gt;
                    &lt;/Row&gt;
                &lt;/Form.Item&gt;
            &lt;/Form&gt;
        )
    }
}

export default connect(
    state =&gt; ({
        list: state.rooms.list.filter(item =&gt; {
            return item.name&amp;&amp;item.name.indexOf(state.rooms.keyword)!=-1;
        }),
        user:state.login.user
    })
)(Rooms);
</code></pre>
<h3 id="t165.4 pages/messages/$id.js">5.4 pages/messages/$id.js <a href="#t165.4 pages/messages/$id.js"> # </a></h3>
<p>pages/messages/$id.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React,{Component} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react&apos;</span>;
<span class="hljs-keyword">import</span> {Layout,Row,Col,Menu,Icon,Breadcrumb,Input,List,Avatar,Spin,Button} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;antd&apos;</span>; 
<span class="hljs-keyword">import</span> styles <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./index.less&apos;</span>;
<span class="hljs-keyword">import</span> messages <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./models/messages&apos;</span>;
<span class="hljs-keyword">import</span> {connect} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;dva&apos;</span>;
<span class="hljs-keyword">const</span> {Header,Sider,Footer,Content}=Layout;
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Messages</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span></span>{
    state={<span class="hljs-attr">collapsed</span>: <span class="hljs-literal">false</span>}
    onCollapse=<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
        <span class="hljs-keyword">this</span>.setState({<span class="hljs-attr">collapsed</span>:!<span class="hljs-keyword">this</span>.state.collapsed});
    }
    handleKeyDown=<span class="hljs-function">(<span class="hljs-params">event</span>) =&gt;</span> {
        <span class="hljs-keyword">let</span> code=event.keyCode;
        <span class="hljs-keyword">let</span> content = event.target.value;
        <span class="hljs-keyword">if</span> (code == <span class="hljs-number">13</span> &amp;&amp; content) {
            <span class="hljs-keyword">this</span>.props.dispatch({
                <span class="hljs-attr">type</span>: <span class="hljs-string">&apos;messages/addMessage&apos;</span>,
                <span class="hljs-attr">payload</span>:{content}
            });
        }
    }
    render() {
        <span class="hljs-keyword">let</span> {messages,users,room,user}=<span class="hljs-keyword">this</span>.props;
        <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.props);
        <span class="hljs-keyword">return</span> (
            &lt;Layout style={{ minHeight: &apos;100vh&apos; }}&gt;
                &lt;Sider
                    collapsible
                    collapsed={this.state.collapsed}
                    onCollapse={this.onCollapse}
                &gt;
                    &lt;h3 className={styles[&apos;room-title&apos;]} &gt;{room.name}&lt;/h3&gt;
                    &lt;Menu style={{padding:&apos;10px&apos;}} theme=&quot;dark&quot; defaultSelectedKeys={[&apos;1&apos;]} mode=&quot;inline&quot;&gt;
                        {
                            users.map(user =&gt; (
                                &lt;Menu.Item key={user._id}&gt;
                                    &lt;img src={user.avatar} style={{width:32,height:32,borderRadius:&apos;5px&apos;}}/&gt;
                                    &lt;span style={{marginLeft: 15}}&gt;{user.name}&lt;/span&gt;
                                &lt;/Menu.Item&gt;
                            ))
                        }
                    &lt;/Menu&gt;
                &lt;/Sider&gt;
                &lt;Layout&gt;
                    &lt;Content style={{margin: &apos;16px&apos;,backgroundColor: &apos;#FFF&apos;}}&gt;
                        &lt;List
                            style={{padding:15}}
                            itemLayout=&quot;horizontal&quot;
                            dataSource={messages}
                            renderItem={
                                message =&gt; (
                                    &lt;List.Item actions={[]}&gt;
                                        &lt;List.Item.Meta
                                            avatar={&lt;Avatar src={message.user.avatar} /&gt;}
                                            title={message.user.name}
                                            description={message.user.email}
                                        /&gt;
                                        &lt;div&gt;{message.content}&lt;/div&gt;
                                    &lt;/List.Item&gt;
                                )
                            }
                        &gt;
                        &lt;/List&gt;
                    &lt;/Content&gt;
                    &lt;Footer style={{textAlign: &apos;center&apos;}}&gt;
                        &lt;Row&gt;
                            &lt;Col span={3}&gt;
                                &lt;img src={user &amp;&amp; user.avatar} style={{height:30,height:30,borderRadius:5}}/&gt;
                                {user&amp;&amp; user.name}&#x8BF4;:
                                &lt;/Col&gt;
                            &lt;Col span={21}&gt;&lt;Input type=&quot;text&quot; onKeyDown={this.handleKeyDown}/&gt;&lt;/Col&gt;
                        &lt;/Row&gt;
                    &lt;/Footer&gt;
                &lt;/Layout&gt;
           &lt;/Layout&gt;
        )
    }
}
export default connect(
    state =&gt; ({
        ...state.messages,
        user:state.login.user
    })
)(Messages);
</code></pre>
<h3 id="t175.5 src/pages/messages/models/messages.js">5.5 src/pages/messages/models/messages.js <a href="#t175.5 src/pages/messages/models/messages.js"> # </a></h3>
<p>src/pages/messages/models/messages.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> pathToRegexp <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;path-to-regexp&apos;</span>;
<span class="hljs-keyword">import</span> io <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;socket.io-client&apos;</span>;
<span class="hljs-keyword">import</span> {routerRedux} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;dva/router&apos;</span>;
<span class="hljs-keyword">let</span> client;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {

    <span class="hljs-attr">namespace</span>: <span class="hljs-string">&apos;messages&apos;</span>,

    <span class="hljs-attr">state</span>: {
        <span class="hljs-attr">room</span>: <span class="hljs-literal">null</span>,
        <span class="hljs-attr">users</span>:[],
        <span class="hljs-attr">messages</span>:[]
    },

    <span class="hljs-attr">subscriptions</span>: {
      setup({dispatch,history}) {
          history.listen(<span class="hljs-function">(<span class="hljs-params">{pathname,query}</span>) =&gt;</span> {
              <span class="hljs-keyword">let</span> result=pathToRegexp(<span class="hljs-string">&apos;/messages/:id&apos;</span>).exec(pathname);
              <span class="hljs-keyword">if</span> (result) {
                  <span class="hljs-keyword">let</span> room=result[<span class="hljs-number">1</span>];
                  dispatch({<span class="hljs-attr">type</span>: <span class="hljs-string">&apos;setRoom&apos;</span>,<span class="hljs-attr">payload</span>: room});
                  dispatch({<span class="hljs-attr">type</span>: <span class="hljs-string">&apos;login/validate&apos;</span>});
                  <span class="hljs-keyword">let</span> socket=io(<span class="hljs-string">&apos;http://127.0.0.1:7001&apos;</span>,{
                      <span class="hljs-attr">query</span>: {<span class="hljs-attr">token</span>:localStorage.getItem(<span class="hljs-string">&apos;token&apos;</span>)||<span class="hljs-string">&apos;&apos;</span>,room}
                  });
                  client=socket;
                  socket.on(<span class="hljs-string">&apos;connect&apos;</span>,() =&gt; {
                      socket.emit(<span class="hljs-string">&apos;getRoom&apos;</span>,room);
                  });
                  socket.on(<span class="hljs-string">&apos;room&apos;</span>,(room) =&gt; {
                      dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;room&apos;</span>,<span class="hljs-attr">payload</span>:room});
                  });
                  socket.on(<span class="hljs-string">&apos;messageAdded&apos;</span>,message =&gt; {
                      dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;messageAdded&apos;</span>,<span class="hljs-attr">payload</span>:message});
                  });
                    socket.on(<span class="hljs-string">&apos;online&apos;</span>,user =&gt; {
                      dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;addUser&apos;</span>,<span class="hljs-attr">payload</span>:user});
                  });
                  socket.on(<span class="hljs-string">&apos;offline&apos;</span>,id =&gt; {
                      dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;delUser&apos;</span>,<span class="hljs-attr">payload</span>:id});
                  });
                  socket.on(<span class="hljs-string">&apos;needLogin&apos;</span>,() =&gt; {
                      dispatch(routerRedux.push(<span class="hljs-string">&apos;/login&apos;</span>));
                    });
                    socket.on(<span class="hljs-string">&apos;disconnect&apos;</span>,() =&gt; {
                        dispatch({<span class="hljs-attr">type</span>: <span class="hljs-string">&apos;login/logout&apos;</span>});
                    });
                    socket.on(<span class="hljs-string">&apos;error&apos;</span>,() =&gt; {
                      dispatch(routerRedux.push(<span class="hljs-string">&apos;/login&apos;</span>));
                  });
              }
          });
      }
    },

    <span class="hljs-attr">effects</span>: {
      *addMessage({ payload }, { call, put,select }) {
          <span class="hljs-keyword">const</span> {<span class="hljs-attr">login</span>:{user},<span class="hljs-attr">messages</span>:{room}}=<span class="hljs-keyword">yield</span> select(<span class="hljs-function"><span class="hljs-params">state</span> =&gt;</span> state);
          <span class="hljs-keyword">let</span> message=payload;
          message.user=user._id;
          message.room=room;
          client.emit(<span class="hljs-string">&apos;addMessage&apos;</span>,message);
      }
    },

    <span class="hljs-attr">reducers</span>: {
      setRoom(state, action) {
          <span class="hljs-keyword">return</span> { ...state, <span class="hljs-attr">room</span>:action.payload};
      },
      room(state,{payload}) {
          <span class="hljs-keyword">return</span> { ...state, ...payload};
      },
      messageAdded(state,action) {
          <span class="hljs-keyword">return</span> {...state,<span class="hljs-attr">messages</span>:[...state.messages,action.payload]};
     },
        addUser(state,{payload}) {
            <span class="hljs-keyword">let</span> existUser=state.users.find(<span class="hljs-function"><span class="hljs-params">user</span> =&gt;</span> user._id==payload._id);
          <span class="hljs-keyword">return</span> existUser?state:{...state,<span class="hljs-attr">users</span>:[...state.users,payload]};
     },
        delUser(state,{payload}) {
          <span class="hljs-keyword">return</span> {...state,<span class="hljs-attr">users</span>:state.users.filter(<span class="hljs-function"><span class="hljs-params">item</span>=&gt;</span>item._id!= payload)};
     }
    }
};
</code></pre>
<h2 id="t186. &#x652F;&#x6301;&#x8868;&#x60C5;">6. &#x652F;&#x6301;&#x8868;&#x60C5; <a href="#t186. &#x652F;&#x6301;&#x8868;&#x60C5;"> # </a></h2>
<h3 id="t196.1 src/pages/messages/$id.js">6.1 src/pages/messages/$id.js <a href="#t196.1 src/pages/messages/$id.js"> # </a></h3>
<p>src/pages/messages/$id.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React,{Component} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react&apos;</span>;
<span class="hljs-keyword">import</span> {Layout,Row,Col,Menu,Icon,Breadcrumb,Input,List,Avatar,Spin,Button,Popover,Card} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;antd&apos;</span>; 
<span class="hljs-keyword">import</span> styles <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./index.less&apos;</span>;
<span class="hljs-keyword">import</span> messages <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./models/messages&apos;</span>;
<span class="hljs-keyword">import</span> {connect} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;dva&apos;</span>;
<span class="hljs-keyword">import</span> expressions <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./expressions&apos;</span>;
<span class="hljs-keyword">import</span> styled <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;styled-components&apos;</span>;
<span class="hljs-keyword">import</span> face <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;../../assets/face.png&apos;</span>;
<span class="hljs-keyword">const</span> {Header,Sider,Footer,Content}=Layout;
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Messages</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span></span>{
    state={<span class="hljs-attr">collapsed</span>: <span class="hljs-literal">false</span>,<span class="hljs-attr">inputVal</span>:<span class="hljs-string">&apos;&apos;</span>}
    onCollapse=<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
        <span class="hljs-keyword">this</span>.setState({<span class="hljs-attr">collapsed</span>:!<span class="hljs-keyword">this</span>.state.collapsed});
    }
    sendMessage=<span class="hljs-function">(<span class="hljs-params">event</span>) =&gt;</span> {
        <span class="hljs-keyword">let</span> content = event.target.value;
        <span class="hljs-keyword">this</span>.props.dispatch({
            <span class="hljs-attr">type</span>: <span class="hljs-string">&apos;messages/addMessage&apos;</span>,
            <span class="hljs-attr">payload</span>:{content}
        });
    }
    handleInputChange=<span class="hljs-function">(<span class="hljs-params">event</span>) =&gt;</span> {
        <span class="hljs-keyword">this</span>.setState({
            <span class="hljs-attr">inputVal</span>:event.target.value
        });
    }
    fillFace=<span class="hljs-function">(<span class="hljs-params">event</span>) =&gt;</span> {
        <span class="hljs-keyword">const</span> {index}=event.currentTarget.dataset;
        <span class="hljs-keyword">this</span>.setState({
            <span class="hljs-attr">inputVal</span>:<span class="hljs-string">`<span class="hljs-subst">${<span class="hljs-keyword">this</span>.state.inputVal}</span>#(<span class="hljs-subst">${index}</span>)`</span>
        });
    }
    render() {
        <span class="hljs-keyword">let</span> {messages,users,room,user}=<span class="hljs-keyword">this</span>.props;
        <span class="hljs-keyword">let</span> faces=(
            <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Row</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{width:512}}</span>&gt;</span>
                {
                    expressions.default.map((item,index) =&gt; (
                        <span class="hljs-tag">&lt;<span class="hljs-name">Col</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{index}</span> <span class="hljs-attr">span</span>=<span class="hljs-string">{3}</span>&gt;</span>
                            <span class="hljs-tag">&lt;<span class="hljs-name">div</span>
                                <span class="hljs-attr">data-index</span>=<span class="hljs-string">{index}</span>
                                <span class="hljs-attr">onClick</span>=<span class="hljs-string">{this.fillFace}</span>
                                <span class="hljs-attr">style</span>=<span class="hljs-string">{{width:</span> &apos;<span class="hljs-attr">64px</span>&apos;,<span class="hljs-attr">height:</span> &apos;<span class="hljs-attr">64px</span>&apos;,<span class="hljs-attr">backgroundImage:</span> `<span class="hljs-attr">url</span>(${<span class="hljs-attr">face</span>})`,<span class="hljs-attr">backgroundPosition:</span> `<span class="hljs-attr">left</span> ${<span class="hljs-attr">-64</span>*<span class="hljs-attr">index</span>+&apos;<span class="hljs-attr">px</span>&apos;}`}}&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                        <span class="hljs-tag">&lt;/<span class="hljs-name">Col</span>&gt;</span>
                    ))
                }
            <span class="hljs-tag">&lt;/<span class="hljs-name">Row</span>&gt;</span></span>
        )
        <span class="hljs-keyword">let</span> facePanel=(
            <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Popover</span> <span class="hljs-attr">content</span>=<span class="hljs-string">{faces}</span> <span class="hljs-attr">title</span>=<span class="hljs-string">&quot;&#x8868;&#x60C5;&quot;</span> <span class="hljs-attr">trigger</span>=<span class="hljs-string">&quot;click&quot;</span>&gt;</span>
                &#x8868;&#x60C5;
            <span class="hljs-tag">&lt;/<span class="hljs-name">Popover</span>&gt;</span></span>
        )
        <span class="hljs-keyword">return</span> (
            &lt;Layout style={{ minHeight: &apos;100vh&apos; }}&gt;
                &lt;Sider
                    collapsible
                    collapsed={this.state.collapsed}
                    onCollapse={this.onCollapse}
                &gt;
                    &lt;h3 className={styles[&apos;room-title&apos;]} &gt;{room.name}&lt;/h3&gt;
                    &lt;Menu style={{padding:&apos;10px&apos;}} theme=&quot;dark&quot; defaultSelectedKeys={[&apos;1&apos;]} mode=&quot;inline&quot;&gt;
                        {
                            users.map(user =&gt; (
                                &lt;Menu.Item key={user._id}&gt;
                                    &lt;img src={user.avatar} style={{width:32,height:32,borderRadius:&apos;5px&apos;}}/&gt;
                                    &lt;span style={{marginLeft: 15}}&gt;{user.name}&lt;/span&gt;
                                &lt;/Menu.Item&gt;
                            ))
                        }
                    &lt;/Menu&gt;
                &lt;/Sider&gt;
                &lt;Layout&gt;
                    &lt;Content style={{margin: &apos;16px&apos;,backgroundColor: &apos;#FFF&apos;}}&gt;
                        &lt;List
                            style={{padding:15}}
                            itemLayout=&quot;horizontal&quot;
                            dataSource={messages}
                            renderItem={
                                message =&gt; {
                                    let content=message.content;
                                    if (!content || content ==&apos;undefined&apos;) return  &lt;div&gt;&lt;/div&gt;;
                                    content=content.replace(/#\((\d+)\)/g,function (matched,index) {
                                        let offset=-64*parseInt(index)+&apos;px&apos;;
                                        return `&lt;span
                                                  style=&quot;display:inline-block;width:64px;height:64px;background-image:url(${face});background-position:left ${offset}&quot;
                                               &gt;&lt;/span&gt;`
                                    });
                                    return (
                                        &lt;List.Item actions={[]}&gt;
                                        &lt;List.Item.Meta
                                            avatar={&lt;Avatar src={message.user.avatar} /&gt;}
                                            title={message.user.name}
                                            description={message.user.email}
                                            /&gt;
                                            &lt;div dangerouslySetInnerHTML={{__html:content}}&gt;&lt;/div&gt;
                                    &lt;/List.Item&gt;
                                    )
                                }
                            }
                        &gt;
                        &lt;/List&gt;
                    &lt;/Content&gt;
                    &lt;Footer style={{textAlign: &apos;center&apos;}}&gt;
                        &lt;Row&gt;
                            &lt;Col span={3}&gt;
                                &lt;img src={user &amp;&amp; user.avatar} style={{height:30,height:30,borderRadius:5}}/&gt;
                                {user&amp;&amp; user.name}&#x8BF4;:
                            &lt;/Col&gt;
                            &lt;Col span={19}&gt;
                                &lt;Input
                                    onChange={this.handleInputChange}
                                    value={this.state.inputVal}
                                    addonBefore={facePanel}
                                    placeholder=&quot;&#x8BF7;&#x8F93;&#x5165;&#x4FE1;&#x606F;&quot;
                                    onPressEnter={this.sendMessage}
                                /&gt;
                            &lt;/Col&gt;
                        &lt;/Row&gt;
                    &lt;/Footer&gt;
                &lt;/Layout&gt;
           &lt;/Layout&gt;
        )
    }
}

export default connect(
    state =&gt; ({
        ...state.messages,
        user:state.login.user
    })
)(Messages);
</code></pre>
<h3 id="t206.2 src/pages/messages/expressions.js">6.2 src/pages/messages/expressions.js <a href="#t206.2 src/pages/messages/expressions.js"> # </a></h3>
<p>src/pages/messages/expressions.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
    <span class="hljs-attr">default</span>: [
        <span class="hljs-string">&apos;&#x5475;&#x5475;&apos;</span>, <span class="hljs-string">&apos;&#x54C8;&#x54C8;&apos;</span>, <span class="hljs-string">&apos;&#x5410;&#x820C;&apos;</span>, <span class="hljs-string">&apos;&#x554A;&apos;</span>, <span class="hljs-string">&apos;&#x9177;&apos;</span>, <span class="hljs-string">&apos;&#x6012;&apos;</span>, <span class="hljs-string">&apos;&#x5F00;&#x5FC3;&apos;</span>, <span class="hljs-string">&apos;&#x6C57;&apos;</span>, <span class="hljs-string">&apos;&#x6CEA;&apos;</span>, <span class="hljs-string">&apos;&#x9ED1;&#x7EBF;&apos;</span>,
        <span class="hljs-string">&apos;&#x9119;&#x89C6;&apos;</span>, <span class="hljs-string">&apos;&#x4E0D;&#x9AD8;&#x5174;&apos;</span>, <span class="hljs-string">&apos;&#x771F;&#x68D2;&apos;</span>, <span class="hljs-string">&apos;&#x94B1;&apos;</span>, <span class="hljs-string">&apos;&#x7591;&#x95EE;&apos;</span>, <span class="hljs-string">&apos;&#x9634;&#x9669;&apos;</span>, <span class="hljs-string">&apos;&#x5410;&apos;</span>, <span class="hljs-string">&apos;&#x54A6;&apos;</span>, <span class="hljs-string">&apos;&#x59D4;&#x5C48;&apos;</span>, <span class="hljs-string">&apos;&#x82B1;&#x5FC3;&apos;</span>,
        <span class="hljs-string">&apos;&#x547C;&apos;</span>, <span class="hljs-string">&apos;&#x7B11;&#x773C;&apos;</span>, <span class="hljs-string">&apos;&#x51B7;&apos;</span>, <span class="hljs-string">&apos;&#x592A;&#x5F00;&#x5FC3;&apos;</span>, <span class="hljs-string">&apos;&#x6ED1;&#x7A3D;&apos;</span>, <span class="hljs-string">&apos;&#x52C9;&#x5F3A;&apos;</span>, <span class="hljs-string">&apos;&#x72C2;&#x6C57;&apos;</span>, <span class="hljs-string">&apos;&#x4E56;&apos;</span>, <span class="hljs-string">&apos;&#x7761;&#x89C9;&apos;</span>, <span class="hljs-string">&apos;&#x60CA;&#x54ED;&apos;</span>,
        <span class="hljs-string">&apos;&#x5347;&#x8D77;&apos;</span>, <span class="hljs-string">&apos;&#x60CA;&#x8BB6;&apos;</span>, <span class="hljs-string">&apos;&#x55B7;&apos;</span>, <span class="hljs-string">&apos;&#x7231;&#x5FC3;&apos;</span>, <span class="hljs-string">&apos;&#x5FC3;&#x788E;&apos;</span>, <span class="hljs-string">&apos;&#x73AB;&#x7470;&apos;</span>, <span class="hljs-string">&apos;&#x793C;&#x7269;&apos;</span>, <span class="hljs-string">&apos;&#x661F;&#x661F;&#x6708;&#x4EAE;&apos;</span>, <span class="hljs-string">&apos;&#x592A;&#x9633;&apos;</span>, <span class="hljs-string">&apos;&#x97F3;&#x4E50;&apos;</span>,
        <span class="hljs-string">&apos;&#x706F;&#x6CE1;&apos;</span>, <span class="hljs-string">&apos;&#x86CB;&#x7CD5;&apos;</span>, <span class="hljs-string">&apos;&#x5F69;&#x8679;&apos;</span>, <span class="hljs-string">&apos;&#x94B1;&#x5E01;&apos;</span>, <span class="hljs-string">&apos;&#x5496;&#x5561;&apos;</span>, <span class="hljs-string">&apos;haha&apos;</span>, <span class="hljs-string">&apos;&#x80DC;&#x5229;&apos;</span>, <span class="hljs-string">&apos;&#x5927;&#x62C7;&#x6307;&apos;</span>, <span class="hljs-string">&apos;&#x5F31;&apos;</span>, <span class="hljs-string">&apos;ok&apos;</span>,
    ],
};
</code></pre>
<h2 id="t21&#x53C2;&#x8003;">&#x53C2;&#x8003; <a href="#t21&#x53C2;&#x8003;"> # </a></h2>
<ul>
<li><a href="https://gitee.com/zhufengpeixun/chat">chat</a></li>
</ul>

        <div class="copyright">Powered by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>. Dependence <a href="https://nodejs.org">Node.js</a> run.</div>
    </div>
    
</div>

<script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.js"></script>
<script>
$('.warpper .page-toc ul ul li a').on('click',function(){
  $('.warpper .page-toc ul ul li a').removeClass('my-active')
  $(this).addClass('my-active')
})
  // if (!$('.understand-me').length) {
  //   var bar = $(window).height() - $('.navbar ').height() - $('.page-toc').position().top;
  //   var count = bar / 26 / 2;
  //   var barHeight = $('.page-toc').outerHeight();
  //   $('.page-toc li').eq(0).children('a').addClass('red');
  //   var arr = [];
  //   $("h1,h2,h3,h4,h5,h6").each(function () {
  //     arr.push($(this).position().top);
  //   });
  //   var timer
  //   function dark() {
  //     clearTimeout(timer)
  //      timer = setTimeout(function () {
  //      var top = Math.abs($('.page-toc > ul').position().top);
  //      var cur = $('.content').scrollTop();
  //      for (var i = arr.length; i >= 0; i--) {
  //        if (arr[i] <= cur) {
  //          break;
  //        }
  //      }
  //      if (i === -1) {
  //        i = 0;
  //      }
  //      $('.page-toc li a').removeClass('red');
  //      $('.page-toc li').eq(i).children('a').addClass('red');
  //      let height = $('.page-toc li').eq(i).position().top-$('.page-toc').height(); // 如果当前的offset出去了 回到中间可好？
  //      $('.page-toc').scrollTop(height+$('.page-toc').height()/2);
  //    },200)
  //   }

  //   $('.content').on('scroll', dark);
  // }
</script>
<style>

    /* ::-webkit-scrollbar{width:14px;}
    ::-webkit-scrollbar-track{background-color:transparent;}
    ::-webkit-scrollbar-thumb{background-color:transparent;}
    ::-webkit-scrollbar-thumb:hover {background-color:transparent}
    ::-webkit-scrollbar-thumb:active {background-color:transparent} */

    .page-toc > ul .red {
        background: #f3f3f3;
        z-index: 1;
        border-left: 3px solid #009a61;
        -webkit-transition: all .2s ease;
        transition: all .2s ease;
        color: #000
    }





</style>
</body>
</html>
